﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Authorization.Common;
using S.Authorization.Common.Dto;
using S.Authorization.Infrastructure.Interface.User;
using S.Authorization.Read.API.Application.Command.UserCommand;
using S.Authorization.Read.API.Dto;
using S.Common.Enums.Organization;
using S.Common.Enums.User;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;

namespace S.Authorization.Read.API.Controllers.User
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserReadController : BaseController
    {
        private readonly UserStrategyDto _userStrategyDto;
        private readonly IAuthorizationService _authorizationService;

        public UserReadController(IMediator mediator, IAuthorizationService authorizationService) : base(mediator)
        {
            _userStrategyDto = new UserStrategyDto();// 实例化 UserStrategyDto 对象
            _authorizationService = authorizationService;
        }
        /// <summary>
        /// 登录功能
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet("LoginUser")]
        public async Task<IActionResult> LoginUser(string username, string password)
        {
            return Ok(await mediator.Send(new UserShowlCommond() { UserName = username, UserPassWord= password }));
        }
        /// <summary>
        /// 负责人下拉框显示
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        
        [HttpGet("GetUser")]
        public async Task<IActionResult> GetUser()
        {
            return Ok(await mediator.Send(new UserSelectCommand() { }));
        }
        /// <summary>
        /// 根据当前登录人获取消息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>

        [HttpGet("GetUserById")]
        public async Task<IActionResult> GetUserById()
        {
            return Ok(await mediator.Send(new GetUserCommand() { ID=UserStrategyDto.UserId}));
        }
        [HttpGet("ID")]
        public async Task<IActionResult> ID()
        {
            var userList = new List<string[]>();
            var user = new string[] { UserStrategyDto.UserId.ToString(), UserStrategyDto.UserTrueName };
            userList.Add(user);
            return Ok(userList);
        }
        [Authorize(Roles = "测试")]
        [HttpGet("RoleName")]
        public IActionResult RoleName()
        {
            var rol = UserStrategyDto.RoleName;
            return Ok(User.IsInRole(rol));
        }
        [Authorize(Roles = "超级管理员,测试")]
        [HttpGet("RoleNames")]
        public IActionResult RoleNames()
        {
            return Ok(2);
        }
        /// <summary>
        /// 人员管理分页显示
        /// </summary>
        /// <returns></returns>
        [HttpPost("GetUserList")]
        public async Task<Pager<GetUserListDto>> GetUserList(UserGetAllPageCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 员工状态枚举
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetStaffStateEnum")]
        public List<object> GetStaffStateEnum()
        {
            List<object> list = new List<object>();
            foreach (var item in Enum.GetValues<StaffStateEnum>())
            {
                list.Add(new
                {
                    name = item.ToString(),
                    value = item,
                });
            }
            return list;
        }


        /// <summary>
        /// 用户学历枚举
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetUserEducationEnum")]
        public List<object> GetUserEducationEnum()
        {
            List<object> list = new List<object>();
            foreach (var item in Enum.GetValues<UserEducationEnum>())
            {
                list.Add(new
                {
                    name = item.ToString(),
                    value = item,
                });
            }
            return list;
        }

        /// <summary>
        /// 证件类型枚举
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetUserIDTypeEnum")]
        public List<object> GetUserIDTypeEnum()
        {
            List<object> list = new List<object>();
            foreach (var item in Enum.GetValues<UserIDTypeEnum>())
            {
                list.Add(new
                {
                    name = item.ToString(),
                    value = item,
                });
            }
            return list;
        }
    }
}
